package com.haois.mp.database.module.remote.service.impl;

import com.google.gson.Gson;
import com.haois.mp.database.util.HttpClientUtil;
import com.haois.mp.database.commom.CommonConstants;
import com.haois.mp.database.module.remote.service.INoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by RuiHaoZ on 2017/12/17 12:49
 */
@Service("iNoticeService")
public class NoticeServiceImpl implements INoticeService {

    private static final Logger logger = LoggerFactory.getLogger(GroupServiceImpl.class);

    @Value("${defined.database.server-url}")
    private String serverUrl;
    private Gson gson = new Gson();

    @Override
    public Map getByMem(String access_token,Map params) {
        String url = serverUrl + CommonConstants.NOTICE_MEM;
        String response = HttpClientUtil.sendGet(url, params, access_token);
        Map result = gson.fromJson(response, Map.class);
        logger.debug("获取所在组织公告返回结果:{}", response);
        return result;
    }

    @Override
    public Map getNoticeByOid(String access_token, String oid) {
        String url = serverUrl + CommonConstants.NOTICE_ORG.replace(CommonConstants.OID, oid);
        String response = HttpClientUtil.sendGet(url, new HashMap(), access_token);
        Map result = gson.fromJson(response, Map.class);
        logger.debug("获取单一组织公告返回结果:{}", response);
        return result;
    }

    @Override
    public Map getNoticeById(String access_token, Integer id) {
        String url = serverUrl + CommonConstants.NOTICE_SEE.replace(CommonConstants.ID, String.valueOf(id));
        String response = HttpClientUtil.sendGet(url, new HashMap(), access_token);
        Map result = gson.fromJson(response, Map.class);
        logger.debug("获取公告详情返回结果:{}", response);
        return result;
    }

    @Override
    public Map getTempMsgById(String access_token, Integer id) {
        String url = serverUrl + CommonConstants.TMSG_SEE.replace(CommonConstants.ID, String.valueOf(id));
        String response = HttpClientUtil.sendGet(url, new HashMap(), access_token);
        Map result = gson.fromJson(response, Map.class);
        logger.debug("获取模板消息详情返回结果:{}", response);
        return result;
    }
}
